package com.godyhm.example.userendport;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set;

public class ReadConfig{
	private static Properties mProperties=new Properties();
	static{
		try{
			File file = new File(Constants.CONFIG_FILE_PATH);
			if(file==null||!file.exists()){
				file.createNewFile();
				PrintWriter writer=new PrintWriter(file);
				writer.write("serverAddress="+Constants.SERVER_ADDR+"\n");
//				writer.write("imageAddress="+Constants.IMAGE_URL);
				writer.flush();
				writer.close();
				mProperties = null;
			}else{
				InputStream in = new FileInputStream(file);
				mProperties.load(in);
			}
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	
	public static String getValue(String key){
		if(mProperties!=null){
			Set<Entry<Object, Object>> set=mProperties.entrySet();
			Iterator<Entry<Object, Object>> it=set.iterator();
			while(it.hasNext()){
				Entry<Object, Object> entry=it.next();
				key=(String)entry.getKey();
				if(key.equalsIgnoreCase(key)){
					return (String)entry.getValue();
				}
			}
			return null;
		}else{
			return null;
		}
	}
}
